package org.lzuploader.gui.listeners.main;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Shell;
import org.lzuploader.gui.WMain;
import org.lzuploader.gui.WOptions;

/** Class used when the user clicks on an options widget.
 * 
 * @author Emmanuel Cron
 *
 */
public class OptionsSelectionListener implements SelectionListener
{
    /** Logger of this class. */
    private static Log log = LogFactory.getLog(OptionsSelectionListener.class);

    /** Used when widget is selected by default.
     * @param e Associated event
     */
    @Override
    public void widgetDefaultSelected(final SelectionEvent e)
    {
        widgetSelected(e);
    }

    /** Used when widget is manually selected.
     * @param e Associated event
     */
    @Override
    public void widgetSelected(final SelectionEvent e)
    {
        log.debug("Opening options window.");
        
        Shell wMainShell = null;
        for (int i = 0 ; i < e.display.getShells().length ; i++)
        {
            if (e.display.getShells()[i].getData() instanceof WMain)
            {
                wMainShell = e.display.getShells()[i];
                break;
            }
        }
        
        new WOptions(wMainShell);
    }

}
